package StackPractice;

import java.util.ArrayList;
import java.util.List;

public class PostOrderTraverse {
    List<Integer> treeNodes = new ArrayList<>();
    public List<Integer> postOrderTraverse(TreeNode root) {
        if (root != null) {
            postOrderTraverse(root.left);
            treeNodes.add(root.val);
            postOrderTraverse(root.right);
        }
        return treeNodes;
    }

    public static void main(String[] args) {
        PostOrderTraverse postOrderTraverse = new PostOrderTraverse();
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(3);
        List<Integer> treeNodes = postOrderTraverse.postOrderTraverse(root);
        for (Integer treeNode : treeNodes) {
            System.out.println(treeNode);
        }
    }
}
